<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>log.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_log_log.js.html">log.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Basic strippable logging definitions.
<a name="line17"></a> * @see http://go/closurelogging
<a name="line18"></a> *
<a name="line19"></a> * @author johnlenz@google.com (John Lenz)
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.log&#39;);
<a name="line23"></a>goog.provide(&#39;goog.log.Level&#39;);
<a name="line24"></a>goog.provide(&#39;goog.log.LogRecord&#39;);
<a name="line25"></a>goog.provide(&#39;goog.log.Logger&#39;);
<a name="line26"></a>
<a name="line27"></a>goog.require(&#39;goog.debug&#39;);
<a name="line28"></a>goog.require(&#39;goog.debug.LogManager&#39;);
<a name="line29"></a>goog.require(&#39;goog.debug.LogRecord&#39;);
<a name="line30"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>/** @define {boolean} Whether logging is enabled. */
<a name="line34"></a>goog.define(&#39;goog.log.ENABLED&#39;, goog.debug.LOGGING_ENABLED);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * @constructor
<a name="line40"></a> * @final
<a name="line41"></a> */
<a name="line42"></a>goog.log.Logger = goog.debug.Logger;
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * @constructor
<a name="line48"></a> * @final
<a name="line49"></a> */
<a name="line50"></a>goog.log.Level = goog.debug.Logger.Level;
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>
<a name="line54"></a>/**
<a name="line55"></a> * @constructor
<a name="line56"></a> * @final
<a name="line57"></a> */
<a name="line58"></a>goog.log.LogRecord = goog.debug.LogRecord;
<a name="line59"></a>
<a name="line60"></a>
<a name="line61"></a>/**
<a name="line62"></a> * Finds or creates a logger for a named subsystem. If a logger has already been
<a name="line63"></a> * created with the given name it is returned. Otherwise a new logger is
<a name="line64"></a> * created. If a new logger is created its log level will be configured based
<a name="line65"></a> * on the goog.debug.LogManager configuration and it will configured to also
<a name="line66"></a> * send logging output to its parent&#39;s handlers.
<a name="line67"></a> * @see goog.debug.LogManager
<a name="line68"></a> *
<a name="line69"></a> * @param {string} name A name for the logger. This should be a dot-separated
<a name="line70"></a> *     name and should normally be based on the package name or class name of
<a name="line71"></a> *     the subsystem, such as goog.net.BrowserChannel.
<a name="line72"></a> * @param {goog.log.Level=} opt_level If provided, override the
<a name="line73"></a> *     default logging level with the provided level.
<a name="line74"></a> * @return {goog.log.Logger} The named logger or null if logging is disabled.
<a name="line75"></a> */
<a name="line76"></a>goog.log.getLogger = function(name, opt_level) {
<a name="line77"></a>  if (goog.log.ENABLED) {
<a name="line78"></a>    var logger = goog.debug.LogManager.getLogger(name);
<a name="line79"></a>    if (opt_level &amp;&amp; logger) {
<a name="line80"></a>      logger.setLevel(opt_level);
<a name="line81"></a>    }
<a name="line82"></a>    return logger;
<a name="line83"></a>  } else {
<a name="line84"></a>    return null;
<a name="line85"></a>  }
<a name="line86"></a>};
<a name="line87"></a>
<a name="line88"></a>
<a name="line89"></a>// TODO(johnlenz): try to tighten the types to these functions.
<a name="line90"></a>/**
<a name="line91"></a> * Adds a handler to the logger. This doesn&#39;t use the event system because
<a name="line92"></a> * we want to be able to add logging to the event system.
<a name="line93"></a> * @param {goog.log.Logger} logger
<a name="line94"></a> * @param {Function} handler Handler function to add.
<a name="line95"></a> */
<a name="line96"></a>goog.log.addHandler = function(logger, handler) {
<a name="line97"></a>  if (goog.log.ENABLED &amp;&amp; logger) {
<a name="line98"></a>    logger.addHandler(handler);
<a name="line99"></a>  }
<a name="line100"></a>};
<a name="line101"></a>
<a name="line102"></a>
<a name="line103"></a>/**
<a name="line104"></a> * Removes a handler from the logger. This doesn&#39;t use the event system because
<a name="line105"></a> * we want to be able to add logging to the event system.
<a name="line106"></a> * @param {goog.log.Logger} logger
<a name="line107"></a> * @param {Function} handler Handler function to remove.
<a name="line108"></a> * @return {boolean} Whether the handler was removed.
<a name="line109"></a> */
<a name="line110"></a>goog.log.removeHandler = function(logger, handler) {
<a name="line111"></a>  if (goog.log.ENABLED &amp;&amp; logger) {
<a name="line112"></a>    return logger.removeHandler(handler);
<a name="line113"></a>  } else {
<a name="line114"></a>    return false;
<a name="line115"></a>  }
<a name="line116"></a>};
<a name="line117"></a>
<a name="line118"></a>
<a name="line119"></a>/**
<a name="line120"></a> * Logs a message. If the logger is currently enabled for the
<a name="line121"></a> * given message level then the given message is forwarded to all the
<a name="line122"></a> * registered output Handler objects.
<a name="line123"></a> * @param {goog.log.Logger} logger
<a name="line124"></a> * @param {goog.log.Level} level One of the level identifiers.
<a name="line125"></a> * @param {goog.debug.Loggable} msg The message to log.
<a name="line126"></a> * @param {Error|Object=} opt_exception An exception associated with the
<a name="line127"></a> *     message.
<a name="line128"></a> */
<a name="line129"></a>goog.log.log = function(logger, level, msg, opt_exception) {
<a name="line130"></a>  if (goog.log.ENABLED &amp;&amp; logger) {
<a name="line131"></a>    logger.log(level, msg, opt_exception);
<a name="line132"></a>  }
<a name="line133"></a>};
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Logs a message at the Level.SEVERE level.
<a name="line138"></a> * If the logger is currently enabled for the given message level then the
<a name="line139"></a> * given message is forwarded to all the registered output Handler objects.
<a name="line140"></a> * @param {goog.log.Logger} logger
<a name="line141"></a> * @param {goog.debug.Loggable} msg The message to log.
<a name="line142"></a> * @param {Error=} opt_exception An exception associated with the message.
<a name="line143"></a> */
<a name="line144"></a>goog.log.error = function(logger, msg, opt_exception) {
<a name="line145"></a>  if (goog.log.ENABLED &amp;&amp; logger) {
<a name="line146"></a>    logger.severe(msg, opt_exception);
<a name="line147"></a>  }
<a name="line148"></a>};
<a name="line149"></a>
<a name="line150"></a>
<a name="line151"></a>/**
<a name="line152"></a> * Logs a message at the Level.WARNING level.
<a name="line153"></a> * If the logger is currently enabled for the given message level then the
<a name="line154"></a> * given message is forwarded to all the registered output Handler objects.
<a name="line155"></a> * @param {goog.log.Logger} logger
<a name="line156"></a> * @param {goog.debug.Loggable} msg The message to log.
<a name="line157"></a> * @param {Error=} opt_exception An exception associated with the message.
<a name="line158"></a> */
<a name="line159"></a>goog.log.warning = function(logger, msg, opt_exception) {
<a name="line160"></a>  if (goog.log.ENABLED &amp;&amp; logger) {
<a name="line161"></a>    logger.warning(msg, opt_exception);
<a name="line162"></a>  }
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/**
<a name="line167"></a> * Logs a message at the Level.INFO level.
<a name="line168"></a> * If the logger is currently enabled for the given message level then the
<a name="line169"></a> * given message is forwarded to all the registered output Handler objects.
<a name="line170"></a> * @param {goog.log.Logger} logger
<a name="line171"></a> * @param {goog.debug.Loggable} msg The message to log.
<a name="line172"></a> * @param {Error=} opt_exception An exception associated with the message.
<a name="line173"></a> */
<a name="line174"></a>goog.log.info = function(logger, msg, opt_exception) {
<a name="line175"></a>  if (goog.log.ENABLED &amp;&amp; logger) {
<a name="line176"></a>    logger.info(msg, opt_exception);
<a name="line177"></a>  }
<a name="line178"></a>};
<a name="line179"></a>
<a name="line180"></a>
<a name="line181"></a>/**
<a name="line182"></a> * Logs a message at the Level.Fine level.
<a name="line183"></a> * If the logger is currently enabled for the given message level then the
<a name="line184"></a> * given message is forwarded to all the registered output Handler objects.
<a name="line185"></a> * @param {goog.log.Logger} logger
<a name="line186"></a> * @param {goog.debug.Loggable} msg The message to log.
<a name="line187"></a> * @param {Error=} opt_exception An exception associated with the message.
<a name="line188"></a> */
<a name="line189"></a>goog.log.fine = function(logger, msg, opt_exception) {
<a name="line190"></a>  if (goog.log.ENABLED &amp;&amp; logger) {
<a name="line191"></a>    logger.fine(msg, opt_exception);
<a name="line192"></a>  }
<a name="line193"></a>};
</pre>


</body>
</html>
